/*************************************************************************
 *                  HONGLING CAPITAL CONFIDENTIAL AND PROPRIETARY
 *
 *                COPYRIGHT (C) HONGLING CAPITAL CORPORATION 2012
 *    ALL RIGHTS RESERVED BY HONGLING CAPITAL CORPORATION. THIS PROGRAM
 * MUST BE USED  SOLELY FOR THE PURPOSE FOR WHICH IT WAS FURNISHED BY
 * HONGLING CAPITAL CORPORATION. NO PART OF THIS PROGRAM MAY BE REPRODUCED
 * OR DISCLOSED TO OTHERS,IN ANY FORM, WITHOUT THE PRIOR WRITTEN
 * PERMISSION OF HONGLING CAPITAL CORPORATION. USE OF COPYRIGHT NOTICE
 DOES NOT EVIDENCE PUBLICATION OF THE PROGRAM.
 *                  HONGLING CAPITAL CONFIDENTIAL AND PROPRIETARY
 *************************************************************************/

package com.hongling.uc.service;

import com.hongling.uc.dao.UserMapper;
import com.hongling.uc.domain.UserDTO;
import com.hongling.uc.mapping.User;
import com.hongling.uc.transform.UserDT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 实现接口方法；
 *
 * @author hongchao zhao at 2019-7-23 15:54
 */
@RestController
@CacheConfig(cacheNames = "usercache")
public class DemoServiceImpl implements DemoService{

    private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);

    @Resource
    private UserMapper userMapper;

    @Value("${server.port}")
    String port;

    @Override
    public String sayHi(String name) {
        logger.debug("调用当前接口" + port);
        return "hello " + name + ",当前端口：" + port;
    }

    @Override
    @Cacheable(key = "'userID#'+ #p0",unless = "#result == null")
    public UserDTO getUserById(Integer userID){
        User user = userMapper.selectByPrimaryKey(userID);
        logger.debug("获取用户信息，user===>" + user);
        return new UserDT().from(user);
    }

}
